package com.answer.controller;


import com.answer.model.dto.app.AppAddDTO;
import com.answer.model.dto.app.AppUpdateDTO;
import com.answer.model.dto.question.QuestionAddDTO;
import com.answer.model.dto.question.QuestionEditDTO;
import com.answer.model.dto.question.QuestionQueryDTO;
import com.answer.model.dto.question.QuestionUpdateDTO;
import com.answer.model.reslut.Result;
import com.answer.model.reslut.ResultPage;
import com.answer.model.vo.AppVo;
import com.answer.model.vo.QuestionVo;
import com.answer.service.QuestionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/question")
public class QuestionController {

    @Resource
    private QuestionService questionService;



    //查询列表
    @PostMapping("/query/all")
    public Result queryAll(@RequestBody QuestionQueryDTO QuestionQueryDTO){
        ResultPage<QuestionVo> questionVoResultPage = questionService.queryAll(QuestionQueryDTO);
        return Result.success(questionVoResultPage);
    }


    //根据id查询
    @GetMapping("/query/one/{id}")
    public Result queryOneById(@PathVariable Long id){
        QuestionVo questionVo = questionService.queryOneById(id);
        return Result.success(questionVo);
    }


    //新增
    @PostMapping("/add")
    public Result register(@RequestBody QuestionAddDTO questionAddDTO){
        Boolean res = questionService.addQuestion(questionAddDTO);
        return res? Result.success("添加成功"):Result.faile("添加失败");
    }

    //修改
    @PostMapping("/update")
    public Result update(@RequestBody QuestionUpdateDTO questionUpdateDTO){
        Boolean res = questionService.updateQuestion(questionUpdateDTO);
        return res? Result.success("修改成功"):Result.faile("修改失败");
    }

    //修改
    @PostMapping("/edit")
    public Result edit(@RequestBody QuestionEditDTO questionEditDTO){
        Boolean res = questionService.editQuestion(questionEditDTO);
        return res? Result.success("修改成功"):Result.faile("修改失败");
    }

    //删除
    @PostMapping("/delete")
    public Result delete(Long id){
        Boolean res = questionService.removeById(id);
        return res? Result.success("删除成功"):Result.faile("删除失败");
    }

    @GetMapping("/questionIdName")
    public Result getQuestionIdAndNameMap(){
        List<HashMap<String, String>> res =  questionService.getQuestinIdAndNameMap();
        return Result.success(res);
    }
}
